<style lang="scss" scoped>
	.content {

		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.nav {
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 100;
	}

	.top {
		padding: 20rpx 0;
	}

	.search {
		width: 690rpx;
		height: 68rpx;
		background: #f4f5f7;
		border: 2rpx solid #f5f5f5;
		border-radius: 46rpx;
		margin: 0rpx auto;
		padding: 20rpx;

		.ipt {
			flex: 1;
		}
	}

	.choose {
		width: 100%;
		height: 100rpx;
		background: #ffffff;

		padding: 20rpx;

		.left {
			flex: 1;
		}

		.line {
			width: 2rpx;
			height: 40rpx;
			background: #dee2ee;
			margin: 0 20rpx;
		}
	}

	.lists {
		margin-bottom: 50rpx;

		.list {
			width: 690rpx;
			height: 332rpx;
			opacity: 1;
			background: #ffffff;
			border-radius: 20rpx;
			box-shadow: 0rpx 30rpx 18rpx -14rpx #e6ebf2;
			overflow: hidden;
			margin-top: 30rpx;

			.head {
				width: 100%;

				.tips {
					width: 136rpx;
					border-bottom: 1px solid #eee;
					border-right: 1px solid #eee;

					.tip {
						height: 68rpx;
					}

					.actived {
						background: #f2c530;
						color: #fff;
					}
				}

				.ordernum {

					padding: 0 20rpx;
					flex: 1;
					border-bottom: 1px solid #eee;

					>view {
						height: 68rpx;
					}

					.between-flex {
						width: 100%;
					}
				}
			}

			.contains {
				width: 100%;
				padding: 20rpx;

				.text {
					width: 620rpx;
					line-height: 60rpx;

					.h1 {
						width: 120rpx;

					}
				}
			}


		}
	}
</style>

<template>
	<view class="content">
		<view class="nav bgwhite" id="nav">
			<view class="top bgwhite">
				<view class="search align-flex">
					<u-icon name="search" color="#666" size="34"></u-icon>
					<input class="ipt p-left20" type="text" v-model="keywords" @input="search" placeholder="搜索单号/关键词" />
				</view>
			</view>
			<u-tabs :list="nav" :is-scroll="false" bar-width="60" bar-height="4" :current="current" @change="change"></u-tabs>
			<u-line margin="10rpx 0 0 0"></u-line>
			<view class="choose between-flex gray f28" v-if="current==0 && !isFactory">
				<view class="left  between-flex" @click="$navTo(PagesCourseRouterConfig.ChooseDept)"><span>{{dept?dept.name:'选择科室'}}</span>
					<u-icon name="arrow-right"></u-icon>
				</view>
				<view class="line"></view>
				<view>共 <span class="textColor">{{total}}</span>条</view>
			</view>
			<view class="choose between-flex gray f28" v-else>
				<view class="left  between-flex" @click="$navTo(PagesCourseRouterConfig.ChooseUnit)"><span>{{unit?unit.name:'选择巡检单元'}}</span>
					<u-icon name="arrow-right"></u-icon>
				</view>
				<view class="line"></view>
				<view>共 <span class="textColor">{{total}}</span>条</view>
			</view>
		</view>
		<view :style="'height:'+navheight+'px;'"></view>
		<view v-if="navheight">
			<view class="lists">
				<view v-for="item,index in list" :key="index">
					<view class="list" v-if="current==0">
						<view class="head flex">
							<view class="tips">
								<view class="tip f28 center-flex  " :class="item.inspectionWhy===0?'actived':''">
									{{item.inspectionWhy===0?'限期整改':'计划巡检'}}
								</view>
							</view>
							<view class="ordernum f28 gray">
								<view class="between-flex">
									<view class="f26 textColor">编号: {{item.assetsCode}}</view>
									<view class="f26 red">
										待巡
									</view>
								</view>
							</view>
						</view>
						<view class="contains between-flex" @click="$navTo(PagesPollingRouterConfig.PollingDetail+'?executeId='+item.executeId)">
							<view class="text">
								<view class="align-flex">
									<view class="gray h1">名称:</view><span class="textColor">{{item.name}}</span>
								</view>
								<view class="align-flex">
									<view class="gray h1">科室:</view><span class="textColor">{{item.useDeptToName}}</span>
								</view>
								<view class="align-flex">
									<view class="gray h1">地址:</view><span class="textColor">{{item.place?item.place:'未填写'}}</span>
								</view>
								<view class="align-flex">
									<view class="gray h1">限期整改:</view><span class="textColor">{{item.endTime}}</span>
								</view>
							</view>
							<u-icon name="arrow-right" color="#98a5b3" size="28"></u-icon>
						</view>

					</view>
					<view class="list" v-else>
						<view class="head flex">
							<view class="tips">
								<view class="tip f28 center-flex  " :class="isXian(item)===1?'actived':''">
									{{isXian(item)===1?'限期整改':'计划巡检'}}
								</view>
							</view>
							<view class="ordernum f28 gray">
								<view class="between-flex">
									<view class="f26 textColor">编号: {{item.code}}</view>
									<view class="f26 red">
										待巡
									</view>
								</view>
							</view>
						</view>
						<view class="contains between-flex" @click="$navTo(PagesPollingRouterConfig.PollingDetail+'?executeId='+item.executeId)">
							<view class="text">
								<view class="align-flex">
									<view class="gray h1">名称:</view><span class="textColor">{{item.name}}</span>
								</view>
								<view class="align-flex">
									<view class="gray h1">使用科室:</view><span class="textColor">{{item.useDeptToName}}</span>
								</view>
								<!-- <view class="align-flex"><view class="gray h1">巡检单元:</view><span class="textColor">{{item.place?item.place:'未填写'}}</span></view> -->
								<view class="align-flex">
									<view class="gray h1">限期整改:</view><span class="textColor">{{item.endTime}}</span>
								</view>
							</view>
							<u-icon name="arrow-right" color="#98a5b3" size="28"></u-icon>
						</view>

					</view>
				</view>

			</view>
			<view class="center-flex c999 f24" v-if="nomore">-没有更多了-</view>
			<view v-if="empty" style="position: fixed;top:40%;left:50%;transform: translateX(-50%);">
				<u-empty text="暂无列表"></u-empty>

			</view>
		</view>

	</view>

</template>

<script>
	import PagesCourseRouterConfig from '@/pagesCourse/routerConfig.js';
	import PagesPollingRouterConfig from '@/pagesPolling/routerConfig.js';
	import { Storage_IsFactory } from '@/common/index.js';
	export default {
		data() {
			return {
				PagesCourseRouterConfig,
				PagesPollingRouterConfig,
				navheight: 0,
				head: this.$head,
				isFactory: false,
				nav: [{
					name: '按科室',
					count: 0
				}, {
					name: '按巡检单元',
					count: 0
				}],
				current: 0,
				dept: null, //选择的科室
				unit: null, //选择的巡检单元
				page: 0,
				list: [],
				nomore: false,
				empty: false,
				keywords: '',
				total: 0
			}
		},
		onLoad() {
			this.isFactory = Storage_IsFactory()
			uni.$on('chooseDept', () => {
				this.reset()
			})
			uni.$on('chooseUnit', () => {
				this.reset()
			})
			setTimeout(() => {
				let info = uni.createSelectorQuery().select("#nav");
				info.boundingClientRect((data) => {

					this.navheight = data.height

					console.log(this.navheight)
				}).exec()
			}, 1000)

		},
		onShow() {
			this.reset()
		},
		beforeDestroy() {
			uni.$off('chooseDept')
			uni.$off('chooseUnit')
		},
		onReachBottom() {
			if (!this.nomore) {
				this.page++
				this.getlist()
			}
		},
		methods: {
			isXian(item) {
				let result = 0
				if (item.lastResult == 2 && item.lastErrorMake == 1) {
					result = 1
				}
				return result
			},
			search() {
				this.$u.debounce(this.reset, 500)

			},
			reset() {
				this.$showloading()
				this.page = 0
				this.list = []
				this.nomore = false
				this.getlist()
			},
			getlist() {
				var url = ''
				if (this.current == 0) {
					url = "/bus/inspection/work/assets/page"
				} else if (this.current == 1) {
					url = "/bus/inspection/work/unit/page"
				}
				var obj = {
					query: this.keywords,
					pageNum: this.page,
					pageSize: 10
				}
				if (this.current == 0 && this.dept) {
					obj.deptId = this.dept.id
				}
				this.$pop.ajaxPost(url, obj).then(res => {
					uni.hideLoading()
					var list = res.body.list
					this.total = res.body.total
					this.list = this.list.concat(list)

					if (this.list.length == 0) {
						this.empty = true
					} else {
						this.empty = false
						if (list.length < 10) {
							this.nomore = true
						} else {
							this.nomore = false
						}
					}
					// console.log(this.list)
				})
			},
			change(index) {
				this.current = index;
				this.reset()
			},

		}
	}
</script>
